package com.mohe.dangjian.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;

import com.mohe.dangjian.model.CommunityParty;
import com.mohe.dangjian.model.LXGeneralParty;
import com.mohe.dangjian.model.LXParty;
import com.mohe.dangjian.model.Member;
import com.mohe.dangjian.service.interfaces.ILXGeneralParty;
import com.mohe.dangjian.service.interfaces.ILXParty;
import com.mohe.dangjian.service.interfaces.IMember;
import com.mohe.dangjian.utils.DateStrUtil;
import com.mohe.dangjian.utils.ExcelException;
import com.mohe.dangjian.utils.ExcelMember;
import com.mohe.dangjian.utils.ExcelUtil;
import com.mohe.dangjian.utils.Json;
import com.mohe.dangjian.utils.JsonUtil;
import com.mohe.dangjian.utils.Page;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 两新党员Action
 * 
 * @author wxm
 * 
 */
public class LXMemberAction extends ActionSupport {

	private static final long serialVersionUID = -8380336599439346545L;
	private static final String partyType = "两新";

	private IMember memberServ;
	private ILXParty lxPartyServ;
	private ILXGeneralParty lxGeneralPartyServ;

	private List<Member> memberList;
	private List<LXParty> lxPartyList;
	private List<LXGeneralParty> lxGeneralPartyList;
	private Page page = new Page();
	private Member member = new Member();
	private LXGeneralParty lxGeneralParty = new LXGeneralParty();
	
	// 消息提示
	private String flag = "";
	// 上传的Excel文件
	private List<File> excel;
	
	private Integer minAge;
	private Integer maxAge;
	// 最早出生日期
	private String minBorn = "";
	// 最晚出生日期
	private String maxBorn = "";
	// 表示从哪跳转到编辑页面，1:主页面/2:查看页面
	private Integer editFrom;
	// 最早参加工作日期
	private String minWorkDate = "";
	// 最晚参加工作日期
	private String maxWorkDate = "";
	// 最早入党日期
	private String minJoinDate = "";
	// 最晚入党日期
	private String maxJoinDate = "";
	// 最早转正日期
	private String minConfirmDate = "";
	// 最晚转正日期
	private String maxConfirmDate = "";	

	public List<Member> getMemberList() {
		return memberList;
	}

	public void setMemberList(List<Member> memberList) {
		this.memberList = memberList;
	}

	public ILXParty getLxPartyServ() {
		return lxPartyServ;
	}

	public void setLxPartyServ(ILXParty lxPartyServ) {
		this.lxPartyServ = lxPartyServ;
	}

	public List<LXParty> getLxPartyList() {
		return lxPartyList;
	}

	public void setLxPartyList(List<LXParty> lxPartyList) {
		this.lxPartyList = lxPartyList;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public IMember getMemberServ() {
		return memberServ;
	}

	public void setMemberServ(IMember memberServ) {
		this.memberServ = memberServ;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public List<File> getExcel() {
		return excel;
	}

	public void setExcel(List<File> excel) {
		this.excel = excel;
	}

	public Integer getMinAge() {
		return minAge;
	}

	public void setMinAge(Integer minAge) {
		this.minAge = minAge;
	}

	public Integer getMaxAge() {
		return maxAge;
	}

	public void setMaxAge(Integer maxAge) {
		this.maxAge = maxAge;
	}

	public String getMinBorn() {
		return minBorn;
	}

	public void setMinBorn(String minBorn) {
		this.minBorn = minBorn;
	}

	public String getMaxBorn() {
		return maxBorn;
	}

	public void setMaxBorn(String maxBorn) {
		this.maxBorn = maxBorn;
	}

	public Integer getEditFrom() {
		return editFrom;
	}

	public void setEditFrom(Integer editFrom) {
		this.editFrom = editFrom;
	}

	public String getMinWorkDate() {
		return minWorkDate;
	}

	public void setMinWorkDate(String minWorkDate) {
		this.minWorkDate = minWorkDate;
	}

	public String getMaxWorkDate() {
		return maxWorkDate;
	}

	public void setMaxWorkDate(String maxWorkDate) {
		this.maxWorkDate = maxWorkDate;
	}

	public String getMinJoinDate() {
		return minJoinDate;
	}

	public void setMinJoinDate(String minJoinDate) {
		this.minJoinDate = minJoinDate;
	}

	public String getMaxJoinDate() {
		return maxJoinDate;
	}

	public void setMaxJoinDate(String maxJoinDate) {
		this.maxJoinDate = maxJoinDate;
	}

	public String getMinConfirmDate() {
		return minConfirmDate;
	}

	public void setMinConfirmDate(String minConfirmDate) {
		this.minConfirmDate = minConfirmDate;
	}

	public String getMaxConfirmDate() {
		return maxConfirmDate;
	}

	public void setMaxConfirmDate(String maxConfirmDate) {
		this.maxConfirmDate = maxConfirmDate;
	}

	public ILXGeneralParty getLxGeneralPartyServ() {
		return lxGeneralPartyServ;
	}

	public void setLxGeneralPartyServ(ILXGeneralParty lxGeneralPartyServ) {
		this.lxGeneralPartyServ = lxGeneralPartyServ;
	}

	public List<LXGeneralParty> getLxGeneralPartyList() {
		return lxGeneralPartyList;
	}

	public void setLxGeneralPartyList(List<LXGeneralParty> lxGeneralPartyList) {
		this.lxGeneralPartyList = lxGeneralPartyList;
	}

	public LXGeneralParty getLxGeneralParty() {
		return lxGeneralParty;
	}

	public void setLxGeneralParty(LXGeneralParty lxGeneralParty) {
		this.lxGeneralParty = lxGeneralParty;
	}

	/**
	 * 获取党员信息列表
	 * 
	 * @return
	 */
	public String getMemberInfoListForPage() {
		member.setPartyType(partyType);
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("minBorn", minBorn);
		paramMap.put("maxBorn", maxBorn);
		paramMap.put("minWorkDate", minWorkDate);
		paramMap.put("maxWorkDate", maxWorkDate);
		paramMap.put("minJoinDate", minJoinDate);
		paramMap.put("maxJoinDate", maxJoinDate);
		paramMap.put("minConfirmDate", minConfirmDate);
		paramMap.put("maxConfirmDate", maxConfirmDate);
		int count = memberServ.getCount(member, paramMap);
		page.setCount(count);
		minBorn = DateStrUtil.ageToFirstBirth(maxAge);
		maxBorn = DateStrUtil.ageToLastBirth(minAge);
		memberList = memberServ.getMemberList(member, page, paramMap);
		lxGeneralPartyList = lxGeneralPartyServ.getAllLXGeneralParty();
		lxPartyList = lxPartyServ.getAllLXParty();
		return "memberInfo.jsp";
	}
	
	/**
	 * 分页
	 */
	public void searchMemberList() {
		member.setPartyType(partyType);
		Json json = new Json();
		List<Map<String, String>> mapList = new ArrayList<Map<String, String>>();
		if(maxAge != null){
			minBorn = DateStrUtil.ageToFirstBirth(maxAge);
		}
		if(minAge != null){
			maxBorn = DateStrUtil.ageToLastBirth(minAge);
		}
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("minBorn", minBorn);
		paramMap.put("maxBorn", maxBorn);
		paramMap.put("minWorkDate", minWorkDate);
		paramMap.put("maxWorkDate", maxWorkDate);
		paramMap.put("minJoinDate", minJoinDate);
		paramMap.put("maxJoinDate", maxJoinDate);
		paramMap.put("minConfirmDate", minConfirmDate);
		paramMap.put("maxConfirmDate", maxConfirmDate);
		int count = memberServ.getCount(member, paramMap);
		page.setCount(count);
		List<Member> list = memberServ.getMemberList(member, page, paramMap);
		if (list != null) {
			int index = (page.getCurrPage() - 1) * page.getPageSize() + 1;
			for (Member s : list) {
				Map<String, String> map = new HashMap<String, String>();
				map.put("index", index + "");
				if (s.getTimeKey() != null) {
					map.put("timeKey", s.getTimeKey() + "");
				} else {
					map.put("timeKey", "0");
				}
				if (!StringUtils.isBlank(s.getName())) {
					map.put("name", s.getName());
				} else {
					map.put("name", "");
				}
				if (!StringUtils.isBlank(s.getSex())) {
					map.put("sex", s.getSex());
				} else {
					map.put("sex", "");
				}
				if (!StringUtils.isBlank(s.getNationality())) {
					map.put("nationality", s.getNationality());
				} else {
					map.put("nationality", "");
				}
				if (!StringUtils.isBlank(s.getNativePlace())) {
					map.put("nativePlace", s.getNativePlace());
				} else {
					map.put("nativePlace", "");
				}
				if (!StringUtils.isBlank(s.getBorn())) {
					map.put("born", s.getBorn());
				} else {
					map.put("born", "");
				}
				if (!StringUtils.isBlank(s.getDegree())) {
					if("-1".equals(s.getDegree())){
						map.put("degree", "其他");
					}else if("0".equals(s.getDegree())){
						map.put("degree", "小学");
					}else if("1".equals(s.getDegree())){
						map.put("degree", "初中");
					}else if("2".equals(s.getDegree())){
						map.put("degree", "技工学校");
					}else if("3".equals(s.getDegree())){
						map.put("degree", "中等专科");
					}else if("4".equals(s.getDegree())){
						map.put("degree", "普通高中");
					}else if("5".equals(s.getDegree())){
						map.put("degree", "大专");
					}else if("6".equals(s.getDegree())){
						map.put("degree", "大学");
					}else if("7".equals(s.getDegree())){
						map.put("degree", "硕士研究生");
					}else if("8".equals(s.getDegree())){
						map.put("degree", "博士研究生");
					}else{
						map.put("degree", "");
					}
				} else {
					map.put("degree", "");
				}
				if (!StringUtils.isBlank(s.getWorkDate())) {
					map.put("workDate", s.getWorkDate());
				} else {
					map.put("workDate", "");
				}
				if (!StringUtils.isBlank(s.getPartyName())) {
					map.put("partyName", s.getPartyName());
				} else {
					map.put("partyName", "");
				}
				if (!StringUtils.isBlank(s.getMemberType())) {
					map.put("memberType", s.getMemberType());
				} else {
					map.put("memberType", "");
				}
				if (!StringUtils.isBlank(s.getJoinDate())) {
					map.put("joinDate", s.getJoinDate());
				} else {
					map.put("joinDate", "");
				}
				if (!StringUtils.isBlank(s.getConfirmDate())) {
					map.put("confirmDate", s.getConfirmDate());
				} else {
					map.put("confirmDate", "");
				}
				if (!StringUtils.isBlank(s.getTitle())) {
					map.put("title", s.getTitle());
				} else {
					map.put("title", "");
				}
				if (!StringUtils.isBlank(s.getNote())) {
					map.put("note", s.getNote());
				} else {
					map.put("note", "");
				}
				if (!StringUtils.isBlank(s.getPartyType())) {
					map.put("partyType", s.getPartyType());
				} else {
					map.put("partyType", "");
				}
				mapList.add(map);
				index++;
			}
		}
		json.setObject(page);
		json.setMap(mapList);
		JsonUtil.writeJson(json);
	}

	/**
	 * 跳转到编辑界面
	 * 
	 * @return
	 */
	public String toEditMemberInfo() {
		member = memberServ.getMemberById(member.getTimeKey());
		lxGeneralPartyList = lxGeneralPartyServ.getAllLXGeneralParty();
		lxPartyList = lxPartyServ.getAllLXParty();
		
		LXParty lxp = new LXParty();
		lxp.setName(member.getPartyName());
		List<LXParty> list = lxPartyServ.getLXPartyList(lxp);
		if(list != null && list.size() > 0){
			LXParty lxp2 = list.get(0);
			lxGeneralParty = lxp2.getLxGeneralParty();
		}
		return "editMember.jsp";
	}
	
	/**
	 * 更新党员信息
	 */
	public void updateMemberInfo(){
		member.setPartyType(partyType);
		// 设置党总支名称
		LXParty party = new LXParty();
		party.setName(member.getPartyName());
		List<LXParty> pList = lxPartyServ.getLXPartyList(party);
		if(pList != null && pList.size() > 0){
			LXParty p = pList.get(0);
			member.setGeneralPartyName(p.getLxGeneralParty().getName());
		}
		Json json = new Json();
		member.setCreateDate(new Date());
		boolean result = memberServ.updateMember(member);
		if (result) {
			json.setMessage("编辑成功");
		} else {
			json.setSuccess(true);
			json.setMessage("编辑失败");
		}
		JsonUtil.writeJson(json);
	}
	
	/**
	 * 跳转到新增界面
	 * 
	 * @return
	 */
	public String toAddMemberInfo() {
		lxGeneralPartyList = lxGeneralPartyServ.getAllLXGeneralParty();
		lxPartyList = lxPartyServ.getAllLXParty();
		return "addMember.jsp";
	}

	/**
	 * 保存新增党员
	 */
	public void saveMemberInfo() {
		member.setPartyType(partyType);
		// 设置党总支名称
		LXParty party = new LXParty();
		party.setName(member.getPartyName());
		List<LXParty> pList = lxPartyServ.getLXPartyList(party);
		if(pList != null && pList.size() > 0){
			LXParty p = pList.get(0);
			member.setGeneralPartyName(p.getLxGeneralParty().getName());
		}
		Json json = new Json();
		boolean result = memberServ.saveMember(member);
		if (result) {
			json.setMessage("新增成功");
		} else {
			json.setSuccess(true);
			json.setMessage("新增失败");
		}
		JsonUtil.writeJson(json);
	}

	/**
	 * 保存新增党员list(excel导入)
	 */
	public String importExcelToMemberList() {
		try {
			List<ExcelMember> emList = new ArrayList<ExcelMember>();
			List<Member> mList = new ArrayList<Member>();
			LinkedHashMap<String,String> fieldMap = new LinkedHashMap<String, String>();
			fieldMap.put("姓名", "name");
			fieldMap.put("性别", "sex");
			fieldMap.put("民族", "nationality");
			fieldMap.put("出生年月", "born");
			fieldMap.put("籍贯", "nativePlace");
			fieldMap.put("所属党组织名称", "partyName");
			fieldMap.put("党员类型", "memberType");
			fieldMap.put("参加工作日期", "workDate");
			fieldMap.put("加入中共党组织日期", "joinDate");
			fieldMap.put("转正日期", "confirmDate");
			fieldMap.put("学历", "degree");
			fieldMap.put("职务名称", "title");
			fieldMap.put("备注", "note");
			String sheetName = "两新";
			FileInputStream in = new FileInputStream(excel.get(0));
			String[] uniqueFileds = new String[]{"姓名","性别","民族","出生年月","籍贯","所属党组织名称","党员类型","参加工作日期","加入中共党组织日期","转正日期","学历","职务名称","备注"};
			emList = ExcelUtil.excelToList(in, sheetName, ExcelMember.class, fieldMap, uniqueFileds);
			
			if(emList != null && emList.size() > 0){
				// emList数据转入mList中
				for(ExcelMember em : emList){
					Member m = new Member();
					m.setName(em.getName());
					m.setSex(em.getSex());
					m.setNationality(em.getNationality());
					m.setBorn(em.getBorn());
					m.setNativePlace(em.getNativePlace());
					m.setPartyName(em.getPartyName());
					m.setMemberType(em.getMemberType());
					m.setWorkDate(em.getWorkDate());
					m.setJoinDate(em.getJoinDate());
					m.setConfirmDate(em.getConfirmDate());
					if("其他".equals(em.getDegree())){
						m.setDegree("-1");
					}else if("小学".equals(em.getDegree())){
						m.setDegree("0");
					}else if("初中".equals(em.getDegree())){
						m.setDegree("1");
					}else if("技工学校".equals(em.getDegree())){
						m.setDegree("2");
					}else if("中等专科".equals(em.getDegree())){
						m.setDegree("3");
					}else if("普通高中".equals(em.getDegree())){
						m.setDegree("4");
					}else if("大专".equals(em.getDegree())){
						m.setDegree("5");
					}else if("大学".equals(em.getDegree())){
						m.setDegree("6");
					}else if("硕士研究生".equals(em.getDegree())){
						m.setDegree("7");
					}else if("博士研究生".equals(em.getDegree())){
						m.setDegree("8");
					}else{
						m.setDegree("");
					}
					m.setTitle(em.getTitle());
					m.setNote(em.getNote());
					
					mList.add(m);
				}	
			}
			
			if(mList != null && mList.size() > 0){
				// 设置党组织类型，并检查党组织名称是否存在
				lxPartyList = lxPartyServ.getAllLXParty();
				boolean pExistFlag = false;
				int existCount = 0;
				Member illegalMember = new Member();
				for (Member member : mList) {
					// 检查党组织是否存在
					for(LXParty party : lxPartyList){
						if(party.getName().equals(member.getPartyName())){
							// 设置党总支名称
							member.setGeneralPartyName(party.getLxGeneralParty().getName());
							//
							existCount++;
							pExistFlag = true;
							break;
						}
					}
					// 该党组织不存在
					if(!pExistFlag){
						// 记录不合法的member
						illegalMember = member;
						break;
					}
					member.setPartyType(partyType);
					pExistFlag = false;
				}
				
				// 所有党组织都存在
				if(mList.size() == existCount){
					boolean result = memberServ.saveMemberList(mList);
					
					if (result) {
						flag = "导入成功";
					} else {
						flag = "导入失败";
					}
				}else{
					flag = "导入失败（不存在名称为'" + illegalMember.getPartyName() + "'的党组织）";
				}	
			}else{
				flag = "导入失败";
			}
		} catch (ExcelException e) {
			flag = e.getMessage();
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			flag = e.getMessage();
			e.printStackTrace();
		}
		
		return getMemberInfoListForPage();
	}
	
	/**
	 * 导出党员信息到Excel
	 */
	public void exportMemberListToExcel(){
		// 解决中文乱码，通过指定的编码解密即可。
		try {
			String name = URLDecoder.decode(member.getName(), "utf-8");
			String sex = URLDecoder.decode(member.getSex(), "utf-8");
			String nationality = URLDecoder.decode(member.getNationality(), "utf-8");
			String born = URLDecoder.decode(member.getBorn(), "utf-8");
			String nativePlace = URLDecoder.decode(member.getNativePlace(), "utf-8");
			String memberType = URLDecoder.decode(member.getMemberType(), "utf-8");
			String workDate = URLDecoder.decode(member.getWorkDate(), "utf-8");
			String joinDate = URLDecoder.decode(member.getJoinDate(), "utf-8");
			String confirmDate = URLDecoder.decode(member.getConfirmDate(), "utf-8");
			String degree = URLDecoder.decode(member.getDegree(), "utf-8");
			String title = URLDecoder.decode(member.getTitle(), "utf-8");
			String note = URLDecoder.decode(member.getNote(), "utf-8");
			if(minAge != null){
				minAge = Integer.valueOf(URLDecoder.decode(minAge.toString(), "utf-8"));
			}
			if(maxAge != null){
				maxAge = Integer.valueOf(URLDecoder.decode(maxAge.toString(), "utf-8"));
			}
			minWorkDate = URLDecoder.decode(minWorkDate, "utf-8");
			maxWorkDate = URLDecoder.decode(maxWorkDate, "utf-8");
			minJoinDate = URLDecoder.decode(minJoinDate, "utf-8");
			maxJoinDate = URLDecoder.decode(maxJoinDate, "utf-8");
			minConfirmDate = URLDecoder.decode(minConfirmDate, "utf-8");
			maxConfirmDate = URLDecoder.decode(maxConfirmDate, "utf-8");
			member.setName(name);
			member.setSex(sex);
			member.setNationality(nationality);
			member.setBorn(born);
			member.setNativePlace(nativePlace);
			member.setMemberType(memberType);
			member.setWorkDate(workDate);
			member.setJoinDate(joinDate);
			member.setConfirmDate(confirmDate);
			member.setDegree(degree);
			member.setTitle(title);
			member.setNote(note);
			// 两新党员
			member.setPartyType(partyType);
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}
		Map<String, String> paramMap = new HashMap<String, String>();
		if(maxAge != null){
			minBorn = DateStrUtil.ageToFirstBirth(maxAge);
		}
		if(minAge != null){
			maxBorn = DateStrUtil.ageToLastBirth(minAge);
		}
		paramMap.put("minBorn", minBorn);
		paramMap.put("maxBorn", maxBorn);
		paramMap.put("minWorkDate", minWorkDate);
		paramMap.put("maxWorkDate", maxWorkDate);
		paramMap.put("minJoinDate", minJoinDate);
		paramMap.put("maxJoinDate", maxJoinDate);
		paramMap.put("minConfirmDate", minConfirmDate);
		paramMap.put("maxConfirmDate", maxConfirmDate);
		List<Member> list = memberServ.getMemberList(member, paramMap);
		if(list != null && list.size() > 0){
			List<ExcelMember> elist = new ArrayList<ExcelMember>();
			for(Member m : list){
				ExcelMember em = new ExcelMember();
				if(!StringUtils.isBlank(m.getName())){
					em.setName(m.getName());
				}else{
					em.setName("");
				}
				if(!StringUtils.isBlank(m.getSex())){
					em.setSex(m.getSex());
				}else{
					em.setSex("");
				}
				if(!StringUtils.isBlank(m.getNationality())){
					em.setNationality(m.getNationality());
				}else{
					em.setNationality("");
				}
				if(!StringUtils.isBlank(m.getBorn())){
					em.setBorn(m.getBorn());
				}else{
					em.setBorn("");
				}
				if(!StringUtils.isBlank(m.getNativePlace())){
					em.setNativePlace(m.getNativePlace());
				}else{
					em.setNativePlace("");
				}
				if(!StringUtils.isBlank(m.getPartyName())){
					em.setPartyName(m.getPartyName());
				}else{
					em.setPartyName("");
				}
				if(!StringUtils.isBlank(m.getMemberType())){
					em.setMemberType(m.getMemberType());
				}else{
					em.setMemberType("");
				}
				if(!StringUtils.isBlank(m.getWorkDate())){
					em.setWorkDate(m.getWorkDate());
				}else{
					em.setWorkDate("");
				}
				if(!StringUtils.isBlank(m.getJoinDate())){
					em.setJoinDate(m.getJoinDate());
				}else{
					em.setJoinDate("");
				}
				if(!StringUtils.isBlank(m.getConfirmDate())){
					em.setConfirmDate(m.getConfirmDate());
				}else{
					em.setConfirmDate("");
				}
				if(!StringUtils.isBlank(m.getDegree())){
					if("-1".equals(m.getDegree())){
						em.setDegree("其他");
					}else if("0".equals(m.getDegree())){
						em.setDegree("小学");
					}else if("1".equals(m.getDegree())){
						em.setDegree("初中");
					}else if("2".equals(m.getDegree())){
						em.setDegree("技工学校");
					}else if("3".equals(m.getDegree())){
						em.setDegree("中等专科");
					}else if("4".equals(m.getDegree())){
						em.setDegree("普通高中");
					}else if("5".equals(m.getDegree())){
						em.setDegree("大专");
					}else if("6".equals(m.getDegree())){
						em.setDegree("大学");
					}else if("7".equals(m.getDegree())){
						em.setDegree("硕士研究生");
					}else if("8".equals(m.getDegree())){
						em.setDegree("博士研究生");
					}else{
						em.setDegree("");
					}
				}else{
					em.setDegree("");
				}
				if(!StringUtils.isBlank(m.getTitle())){
					em.setTitle(m.getTitle());
				}else{
					em.setTitle("");
				}
				if(!StringUtils.isBlank(m.getNote())){
					em.setNote(m.getNote());
				}else{
					em.setNote("");
				}
				elist.add(em);
			}
			LinkedHashMap<String,String> fieldMap = new LinkedHashMap<String, String>();
			fieldMap.put("name", "姓名");
			fieldMap.put("sex", "性别");
			fieldMap.put("nationality", "民族");
			fieldMap.put("born", "出生年月");
			fieldMap.put("nativePlace", "籍贯");
			fieldMap.put("partyName", "所属党组织名称");
			fieldMap.put("memberType", "党员类型");
			fieldMap.put("workDate", "参加工作日期");
			fieldMap.put("joinDate", "加入中共党组织日期");
			fieldMap.put("confirmDate", "转正日期");
			fieldMap.put("degree", "学历");
			fieldMap.put("title", "职务名称");
			fieldMap.put("note", "备注");
			String sheetName = "两新";
			HttpServletResponse response = ServletActionContext.getResponse();
			OutputStream out;
			try {
				out = response.getOutputStream();
				ExcelUtil.listToExcel(elist, fieldMap, sheetName, elist.size(), response, out);
			} catch (IOException | ExcelException e) {
				e.printStackTrace();
			}  	
		}
	}

	/**
	 * 删除党员
	 */
	public void delMemberInfo() {
		Json json = new Json();
		boolean result = memberServ.delMember(member.getTimeKey());
		if (result) {
			json.setMessage("删除成功");
		} else {
			json.setSuccess(true);
			json.setMessage("删除失败");
		}
		JsonUtil.writeJson(json);
	}
	
	public void getAllPartyList() {
		Json json = new Json();
		List<Map<String, String>> mapList = new ArrayList<Map<String, String>>();
		List<LXParty> list = lxPartyServ.getAllLXParty();
		if (list != null) {
			for (LXParty s : list) {
				Map<String, String> map = new HashMap<String, String>();
				if (s.getTimeKey() != null) {
					map.put("timeKey", s.getTimeKey() + "");
				} else {
					map.put("timeKey", "0");
				}
				if (!StringUtils.isBlank(s.getName())) {
					map.put("name", s.getName());
				} else {
					map.put("name", "");
				}
				if (!StringUtils.isBlank(s.getAddress())) {
					map.put("address", s.getAddress());
				} else {
					map.put("address", "");
				}
				if (!StringUtils.isBlank(s.getType())) {
					map.put("type", s.getType());
				} else {
					map.put("type", "");
				}
				if (s.getWorkerNum() != null) {
					map.put("workerNum", s.getWorkerNum().toString());
				} else {
					map.put("workerNum", "");
				}
				if (!StringUtils.isBlank(s.getLeaderName())) {
					map.put("leaderName", s.getLeaderName());
				} else {
					map.put("leaderName", "");
				}
				if (!StringUtils.isBlank(s.getLeaderTitle())) {
					map.put("leaderTitle", s.getLeaderTitle());
				} else {
					map.put("leaderTitle", "");
				}
				if (!StringUtils.isBlank(s.getContacts())) {
					map.put("contacts", s.getContacts());
				} else {
					map.put("contacts", "");
				}
				if (!StringUtils.isBlank(s.getContactsTel())) {
					map.put("contactsTel", s.getContactsTel());
				} else {
					map.put("contactsTel", "");
				}
				if (!StringUtils.isBlank(s.getFax())) {
					map.put("fax", s.getFax());
				} else {
					map.put("fax", "");
				}
				if (!StringUtils.isBlank(s.getZip())) {
					map.put("zip", s.getZip());
				} else {
					map.put("zip", "");
				}
				mapList.add(map);
			}
		}
		json.setObject(null);
		json.setMap(mapList);
		JsonUtil.writeJson(json);
	}
	
	/**
	 * 显示详细信息
	 * @return
	 */
	public String toShowMemberInfo(){
		member = memberServ.getMemberById(member.getTimeKey());
		return "showMember.jsp";
	}
}
